<?php
/**
 * @version		$Id: controller.php 14974 2010-02-21 14:32:22Z ian $
 * @package		Joomla
 * @subpackage	Contact
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.controller' );

/**
 * Contact Component Controller
 *
 * @static
 * @package		Joomla
 * @subpackage	Contact
 * @since 1.5
 */
class PopupController extends JController
{
	/**
	 * Display the view
	 */
	function display()
	{
		parent::display();
	}

	/**
	 * Save and send mail
	 *
	 * @static
	 * @since 1.0
	 */
	function submit()
	{
		global $mainframe;
        jimport('joomla.mail.helper');
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		// Initialize some variables
		$db			= & JFactory::getDBO();
		$SiteName	= $mainframe->getCfg('sitename');
        
		$data['emailpopup']	  = JRequest::getVar( 'emailpopup',		'',	        'post' );
		$data['telephonepopup']	  = JRequest::getVar( 'telephonepopup',		'',	        'post' );
		if($data['telephonepopup'] == 'Indtast din telefon-nr'){
			$data['telephonepopup'] = '';
		}
        $subject = "Send mail from user\n";
        $MailFrom 	= $mainframe->getCfg('mailfrom');
		$FromName 	= $mainframe->getCfg('fromname');

        if($data['emailpopup']){
            //Send mail
            $prefix = "Register User\n";
            $body_1  = $prefix."\n";
            $body_1 .= "Email: " .$data['emailpopup'] . "\n";
			$body_1 .= "Telefon: ".$data['telephonepopup'] . "\n";
			$body_1 .= "\nMed venlig hilsen \n";
			$body_1 .= "My Web Creations Denmark \n";
            
			$mail = JFactory::getMailer();

			$mail->addRecipient(array($MailFrom,'henrik@mywebcreations.dk'));
			$mail->setSender( array($data['emailpopup'],"User")  );
			$mail->setSubject( $FromName.': '.$subject );
			$mail->setBody( $body_1 );

			$sent = $mail->Send();
			
			$subject = "www.mywebcreations.dk\n";
			$prefix = "Tak for din tilmelding til My Web Creations nyhedsmail!\n";
            $body_1  = $prefix."\n";
			$body_1 .= "\nMed venlig hilsen \n";
			$body_1 .= "My Web Creations Denmark I/S \n";
			$body_1 .= "info@mywebcreations.dk \n";
            
			$mail = JFactory::getMailer();

			$mail->addRecipient($data['emailpopup']);
			$mail->setSender( array($MailFrom,$FromName)  );
			$mail->setSubject( $FromName.': '.$subject );
			$mail->setBody( $body_1 );

			$sent = $mail->Send();
        
        }
		$msg = JText::_( 'Thank you for your e-mail');
		$link = JRoute::_('index.php', false);
        $this->setRedirect($link, $msg);
	}

}
